package com.example.demo.modules.es.controller;

import com.example.demo.modules.es.entity.User;
import com.example.demo.modules.es.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/es/user")
@Api(tags = "es模块")
public class UserController {
    @Resource
    private UserService userService;

    @PostMapping("/createIndex")
    @ApiOperation(value = "创建索引", notes = "创建索引")
    public String createIndex(String indexName){
        if(StringUtils.isEmpty(indexName)){
            return "请输入索引名称！";
        }
        String result = userService.createIndex(indexName);
        return result;
    }

    @DeleteMapping("/deleteIndex")
    @ApiOperation(value = "删除索引", notes = "删除索引")
    public String deleteIndex(String indexName){
        if(StringUtils.isEmpty(indexName)){
            return "请输入索引名称！";
        }
        String result = userService.deleteIndex(indexName);
        return result;
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增/更新数据", notes = "新增/更新数据")
    public String save(User user){
        return userService.save(user);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除数据", notes = "删除数据")
    public String delete(@PathVariable("id")String id){
        return userService.delete(id);
    }


}
